<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
<style type="text/css">
	/* 解决table中纯英文不换行 */
	#dynamic-table td {word-break: break-all;white-space: pre-wrap;max-width: 27%;}
	#dynamic-table td:nth-child(1) {width: 27%;}
	#dynamic-table td:nth-child(2) {width: 27%;}
</style>
<div class="page-header">
	<h1>
        管理员发布相册列表
		<!-- 管理员权限 -->
		<?php if($rmxUser['user_type'] == USER_TYPE_SCHOOL): ?>
			<a href="<?=admin_url('contents/album_by_admin_edit')?>" class="btn btn-info a-custom">
				<i class="ace-icon fa fa-plus"></i> 发布相册
			</a>
		<?php endif ?>
	</h1>
</div>
<div class="col-xs-12 content-filter">
	<div class="widget-box">
		<div class="widget-header">
			<h4 class="widget-title">内容筛选</h4>
			<div class="widget-toolbar">
				<a href="#" data-action="collapse">
					<i class="ace-icon fa fa-chevron-up"></i>
				</a>
				<a href="#" data-action="close">
					<i class="ace-icon fa fa-times"></i>
				</a>
			</div>
		</div>
		<div class="widget-body">
			<div class="widget-main">
				<div class="form-inline keyword-search-div">
					<label class="keyword-search-label">标题</label>
					<div class="keyword-search-box">
						<div class="div-search">
							<input style="float:left;height:30px;width:220px;border:1px solid #669FC7;padding:0 30px 0 14px;border-radius:10px 0 0 10px !important;-moz-border-radius:10px 0 0 10px;" type="text" name="title" placeholder="搜索标题..." autocomplete="off">
							<span id="empty-search" style="position:relative;right:64px;cursor:pointer;display:none;">×</span>
							<button id="btn-search" class="btn-search" style="outline:none;float:left;height:30px;width:44px;border:1px solid #669FC7;background-color:#669FC7;border:0;border-radius:0 10px 10px 0;-moz-border-radius:0 10px 10px 0;">
								<i class="ace-icon fa fa-search nav-search-icon white"></i>
							</button>
						</div>
					</div>
				</div>
				<div class="form-inline keyword-search-div">
					<label class="keyword-search-label">年级</label>
					<div class="keyword-search-box">
						<a href="javascript:;" class="keyword-search-keyword keyword-search-grade active" data-id="0">全部</a>
						<?php foreach($gradeList as $grade): ?>
							<a href="javascript:;" class="keyword-search-keyword keyword-search-grade" data-id="<?=$grade['id']?>"><?=$grade['grade_name']?></a>
						<?php endforeach; ?>
					</div>
				</div>
				<div>
					<div class="form-inline keyword-search-div">
						<label class="keyword-search-label">班级</label>
						<div class="keyword-search-box div-classes">
							<a href="javascript:;" class="keyword-search-keyword keyword-search-class active" data-id="0">全部</a>	
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="col-xs-12">
	<table id="dynamic-table" class="table table-striped table-bordered table-hover" style="margin-top:10px">
		<thead>
			<tr>
				<th>相册标题</th>
				<th style="max-width: 27%">发送班级</th>
				<th>发布时间</th>
				<th>修改时间</th>
				<?php if($rmxUser['user_type'] == USER_TYPE_SCHOOL): ?>
					<th>操作</th>
				<?php endif ?>
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
</div>

<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<script type="text/javascript">
	// 班级数据
	var classJson = <?= $classList ?>;
	$(function(){
		// 班级表格
		var table = $('#dynamic-table').dt({
			"ajaxUrl": '<?=admin_url('contents/get_category_by_admin_list')?>',
			"columns": [
	            {"data": "title"},
	            {"data": function(ret){
	            	var html = "";
	            	for(var i in ret.classList) html += '<span class="label label-success mr10">'+ ret.classList[i]['class_name'] +'</span>';
	            	return html;
	            }},
	            {"data": "createtime"},
	            {"data": "updatetime"},
				<?php if($rmxUser['user_type'] == USER_TYPE_SCHOOL): ?>
					{"data": function(ret){
						var action = '';
						// 如果是教师权限，只有任课班级的才能修改或删除
						// if(ret.role_change) {
							action += '<a class="green" href="<?=admin_url('contents/album_by_admin_edit')?>/'+ ret.id +'"><i class="fa fa-edit"></i> 编辑</a>';
							action += '&nbsp;&nbsp;&nbsp;&nbsp;<a class="text-danger delete-video" href="javascript:" data-id=' + ret.id +  ' data-title=' + ret.title + '><i class="fa fa-times"></i> 删除</a>';
						// }
						return action;
					}},
				<?php endif ?>
			]
		});

		// 内容筛选
		$("#data-search-btn").click(function(){
			table.setAjaxData({
				"gradeId": $("#data-search-grade").val()
			});
		})
		// 点击关键字
		$("body").on("click", ".keyword-search-keyword", function(){
			var id = $(this).data("id");
			// 高亮当前点击对象
			$(this).parent().find(".keyword-search-keyword").removeClass("active");
			$(this).addClass("active");
			// 如果是点击年级
			if($(this).hasClass("keyword-search-grade")) {
				// 获取班级列表
				$(".keyword-search-class:gt(0)").remove();
				var classList = classJson[id];
				for(var i in classList) $(".keyword-search-class:first").parent().append('<a href="javascript:;" class="keyword-search-keyword keyword-search-class" data-id="'+ classList[i].id +'">'+ classList[i].name +'</a>');
				// 点击班级筛选
				$(".keyword-search-class:first").trigger("click");
			} else {
				var title = $("[name=title]").val();
				// 筛选班级
				table.setAjaxData({
					"class_id": id,
					'title': title
				});
			}
		});
		// 敲回车就搜索
		$("[name=title]").keypress(function (e) {
                if (e.which == 13) {
                    $("#btn-search").trigger("click");
                }
		});
		// 清空搜索框
		$("[name=title]").keyup(function() {
			if($(this).val().length > 0) {
				$("#empty-search").show();
			} else {
				$("#empty-search").hide();
			}
		});
		$("#empty-search").click(function(){
			$("[name=title]").val('');
			$(this).hide();
			// 重置搜索结果
			var classId = $(".div-classes > .active").data("id");
			table.setAjaxData({
				"class_id": classId
			});
		})
		// 搜索标题
		$("#btn-search").click(function() {
			var title = $("[name=title]").val();
			var classId = $(".div-classes > .active").data("id");
			if(title != '') {
				table.setAjaxData({
					"class_id": classId,
					'title': title
				})
			} else {
				table.setAjaxData({
					"class_id": classId,
				})
			}
		});
		// 删除班级视频
		$("body").on('click', '.delete-video', function() {
			var id = $(this).data('id');
			var title = $(this).data('title');
			var posturl = "<?= admin_url("contents/delete_album_by_admin_action") ?>";
			var data = {
				'id': id
			};
			layer.confirm('确定删除：' + title + '？', { title:"提示", offset: '160px' }, function(){
				ajax_post(posturl, data, function() {
					// 刷新页面
					window.location.reload();
				});
			});
		});
	})
</script>